package com.ag.lzm.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.ag.admin.service.IAuthorizeService;

public class AuthorizeTag extends TagSupport implements ApplicationContextAware {
	private static final long serialVersionUID = -5082619765870671777L;

	private static ApplicationContext context;// 声明一个静态变量保存

	private IAuthorizeService authorize;

	private String permission;

	@Override
	public int doStartTag() throws JspException {
		authorize = (IAuthorizeService) context.getBean("AuthorizeImpl");
		//authorize.te();
		JspWriter out = this.pageContext.getOut();
		try {
			out.print("<div><script>alert('tag');</script>" + getPermission());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	@Override
	public int doEndTag() throws JspException {
		JspWriter out = this.pageContext.getOut();
		try {
			out.print("Hello World" + getPermission() + "</div>");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doEndTag();
	}

	@Override
	public void setApplicationContext(ApplicationContext contex)
			throws BeansException {
		this.context = contex;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public static ApplicationContext getContext() {
		return context;
	}

}
